package algorithms.leecode;

public class Au1750 {
    public static void main(String[] args) {
        System.err.println(new Au1750().minimumLength("cabaabac"));
    }
    public int minimumLength(String s) {
        int start = 0;
        int end = s.length() - 1;
        while (start < end) {
            char cS = s.charAt(start);
            char cE = s.charAt(end);
            if (cE != cS) {
                return end -start + 1;
            }
            while (end > start && s.charAt(end) == s.charAt(end - 1)) {
                end --;
                if (end == start) {
                    return 0;
                }
            }
            while (end > start && s.charAt(start + 1) == s.charAt(start)) {
                start++;
                if (end == start) {
                    return 0;
                }
            }
            end--;
            start++;
        }
        return  end -start + 1;
    }
}
